package com.ews.onlineexchange.shiro;

import com.ews.onlineexchange.service.UserService;
import org.apache.shiro.SecurityUtils;

import javax.enterprise.context.RequestScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.IOException;

/**
 * @program: SdewsOnlineExchange
 * @description:
 * @author: wangchangqing
 * @create: 2020-12-29 14:30
 **/
@Named
@RequestScoped
public class Logout {
    @Inject
    UserService userService;
    public static final String HOME_URL = "/index.xhtml";

    public void submit() throws IOException {
        SecurityUtils.getSubject().logout();
        userService.setLoginedUser(null);
        FacesContext.getCurrentInstance().getExternalContext().invalidateSession();
        FacesContext.getCurrentInstance().getExternalContext().redirect(HOME_URL);
    }

}
